// pages/appLetWork/work10/index.js
let ctx = wx.createCanvasContext('myCanvas')
Page({
  data: {
    mosaic: true,
    imagepath: ''
  },
  onClickLeft() {
    wx.navigateBack({
      delta: 1,
    })
  },

  open() {
    wx.chooseImage({
      count: 1,
    }).then(res => {
      console.log(res)
      ctx.drawImage(res.tempFilePaths[0], 0, 0, 300, 380)
      ctx.draw()
    })
  },
  //打码
  mak() {
    this.setData({
      mosaic: true
    })
  },
  //清除
  clear() {
    this.setData({
      mosaic: false
    })
  },
  //盖章
  stamp() {
    ctx.setFillStyle('blue')
    ctx.setFontSize(24)
    ctx.fillText("07201024梁永豪", 100, 100)
    ctx.draw(true)
  },
  //保存
  save() {
    wx.canvasToTempFilePath({
      canvasId: 'myCanvas',
    }).then(res => {
      this.setData({
        imagepath: res.tempFilePath
      })
    })
  },
  //上传
  upload() {

  },
  //手指移动
  move: function (e) {
    //打马赛克
    if (this.data.mosaic) {
      ctx.setFillStyle('red')
      ctx.fillRect(e.touches[0].x, e.touches[0].y, 10, 10)
      ctx.fillRect(e.touches[0].x + 10, e.touches[0].y + 10, 10, 10)
      ctx.setFillStyle('pink')
      ctx.fillRect(e.touches[0].x + 10, e.touches[0].y, 10, 10)
      ctx.fillRect(e.touches[0].x, e.touches[0].y + 10, 10, 10)
      ctx.draw(true)
    }
    //擦除
    else {
      ctx.clearRect(e.touches[0].x, e.touches[0].y, 20, 20)
      ctx.draw(true)
    }
  }
})